package com.sxw.hw_student.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxw.hw_student.system.entity.StudentCourse;
import com.sxw.hw_student.system.mapper.StudentCourseMapper;
import com.sxw.hw_student.system.service.IStudentCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentCourseServiceImpl implements IStudentCourseService {

    @Autowired
    private StudentCourseMapper studentCourseMapper;

    @Override
    public List<StudentCourse> search(String keyword) {
        QueryWrapper<StudentCourse> wrapper = new QueryWrapper<>();
        if (keyword != null && !keyword.trim().isEmpty()) {
            wrapper.lambda()
                    .like(StudentCourse::getStudentNo, keyword)
                    .or()
                    .like(StudentCourse::getCourseNo, keyword);
        }
        return studentCourseMapper.selectList(wrapper);
    }

    @Override
    public void update(StudentCourse course) {
        studentCourseMapper.updateById(course);
    }

    @Override
    public void delete(Integer id) {
        studentCourseMapper.deleteById(id);
    }

    @Override
    public void add(StudentCourse course) {
        studentCourseMapper.insert(course);
    }

    @Override
    public List<StudentCourse> list(QueryWrapper<StudentCourse> wrapper) {
        return studentCourseMapper.selectList(wrapper);
    }

    @Override
    public IPage<StudentCourse> queryStudentCoursePage(Page<StudentCourse> page,
                                                       QueryWrapper<StudentCourse> search) {
        return studentCourseMapper.selectPage(page, search);
    }
}